package cc.customer.web.CAppNews;

import cc.customer.authorization.annotation.CurrentUser;
import cc.customer.cAppNews.CAppNewsService;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.rabbit.domain.CAppNews;
import cc.customer.system.domain.MyUser;
import cc.customer.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @MethodName: $
 * @Description: TODO
 * @Param: $
 * @Return: $
 * @Author: cunfeng
 * @Date: 2020/6/13 9:03
 **/
@Controller
@RequestMapping("/app/cNews")
public class CAppNewsController  extends BaseController {



    @Autowired
    private CAppNewsService cAppNewsService;


    /**
     * 添加消息
     * @param cAppNews
     * @param user
     * @return
     */
    @RequestMapping("/addCAppNews")
    @ResponseBody
    public ResponseBo addCAppNews(CAppNews cAppNews, @CurrentUser MyUser user){
        cAppNews.setcConvUsers(user.getUserUuid());
        return cAppNewsService.addCAppNews(cAppNews);
    }


    /**
     * 消息列表
     * @param cAppNews
     * @param request
     * @param user
     * @return
     */
    @RequestMapping(value = "/cAppNewsList")
    @ResponseBody
    public ResponseBo cAppNewsList(CAppNews cAppNews, QueryRequest request,@CurrentUser MyUser user){
        cAppNews.setcConvUsers(user.getUserUuid());
        return ResponseBo.ok(super.selectByPageNumSize(request, () -> this.cAppNewsService.cAppNewsList(cAppNews)));
    }


    @RequestMapping(value = "/cAppNewsAllCount")
    @ResponseBody
    public Map<String,Object> cAppNewsAllList( @CurrentUser MyUser user){
        Map<String,Object> map = new HashMap<String,Object>();
        List<CAppNews> list = new ArrayList<CAppNews>();
        CAppNews cAppNews = new CAppNews();
        try {
            int i=0;
             //领取
            cAppNews.setcConvNtype("3");
            cAppNews.setType("1");
            cAppNews.setcConvUsers(user.getUserUuid());
            list = this.cAppNewsService.cAppNewsList(cAppNews);
            map.put("receive",list.size());

            i+=list.size();
            // 共享客户
            cAppNews.setcConvNtype("4");
            cAppNews.setType("1");
            list = this.cAppNewsService.cAppNewsList(cAppNews);

            map.put("share",list.size());
            i+=list.size();
            //转让客户
            /*cAppNews.setcConvNtype("2");
            cAppNews.setType("1");
            list = this.cAppNewsService.cAppNewsList(cAppNews);
            i+=list.size();

             */
            map.put("transfer",0);
            map.put("code",0);
            map.put("msg","查询成功");


            map.put("unread",i);
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code",500);
            map.put("msg","查询失败");
            return map;
        }


    }



    /**
     * 我的消息详情
     * @param cAppNews
     * @param user
     * @return
     */
    @RequestMapping("/selectCAppNews")
    @ResponseBody
    public ResponseBo selectCAppNews(CAppNews cAppNews, @CurrentUser MyUser user){
        return cAppNewsService.selectCAppNews(cAppNews);
    }


    /**
     * 立即处理
     * @param cAppNews
     * @param user
     * @return
     */
    @RequestMapping("/cAppNewsUpdate")
    @ResponseBody
    public ResponseBo cAppNewsUpdate(CAppNews cAppNews, @CurrentUser MyUser user){
        return cAppNewsService.cAppNewsUpdate(cAppNews);
    }


}
